/*
 * @Author: minglic minglic@foxmail.com
 * @Date: 2023-10-28 10:31:20
 * @LastEditors: minglic minglic@foxmail.com
 * @LastEditTime: 2023-11-04 17:12:39
 * @FilePath: \go2023\core\entity\user.go
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package entity

import "gorm.io/gorm"

type User struct {
	ID        string `json:"id" gorm:"column:id"`                          // id
	UserName  string `json:"username" gorm:"column:username"`              // 用户名
	Password  string `json:"password" gorm:"column:password"`              // 密码
	Image     string `json:"image" gorm:"column:image"`                    // 头像地址
	CreatedAt int64  `json:"createdAt" gorm:"column:createdAt"`            // 创建日子
	TenantID  uint   `gorm:"foreignKey:Tenants"`                           // 租户ID
	Tenant    Tenant `gorm:"constraint:OnUpdate:CASCADE;OnDelete:CASCADE"` // 租户
}

func (*User) TableName() string {
	return "sys_user"
}

// Tenants 租户表
type Tenant struct {
	gorm.Model
	Name        string
	Description string
}

// Permissions 权限表
type Permission struct {
	gorm.Model
	Name        string
	Description string
}

type Role struct {
	gorm.Model
	Name string //角色名称
	Desc string //说明
}

// RolePermissions 角色-权限关联表
type RolePermission struct {
	RoleID       uint       `gorm:"foreignKey:Role"`
	PermissionID uint       `gorm:"foreignKey:Permission"`
	Role         Role       `gorm:"constraint:OnUpdate:CASCADE;OnDelete:CASCADE"`
	Permission   Permission `gorm:"constraint:OnUpdate:CASCADE;OnDelete:CASCADE"`
}

// Menus 菜单表
type Menu struct {
	gorm.Model
	Name     string
	ParentID *uint
	URL      string
	Icon     string
}

// MenuPermissions 菜单-权限关联表
type MenuPermission struct {
	MenuID       uint       `gorm:"foreignKey:Menu"`
	PermissionID uint       `gorm:"foreignKey:Permission"`
	Navigation   Menu       `gorm:"constraint:OnUpdate:CASCADE;OnDelete:CASCADE"`
	Permission   Permission `gorm:"constraint:OnUpdate:CASCADE;OnDelete:CASCADE"`
}
